package com.example.jsf.controller;

import com.example.jsf.Repository.IncomeRepository;
import com.example.jsf.Repository.UserRepository;

import com.example.jsf.entity.User;
import com.example.jsf.other.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class userController {

    @Autowired
    private UserRepository userRepository;

    @PostMapping("login")
    public Result addIncome(@RequestBody User user) {
        System.out.println(user.getUserName());
        User isName = userRepository.findByUserName(user.getUserName());
        if( isName !=null ){
            if(user.getPassWord().equals(isName.getPassWord())){
                System.out.println("success");
                return Result.success(isName);
            }else{
                return Result.fail("密码错误");
            }
        }
        return Result.fail("用户名错误");
    }
}
